package com.ricchieri.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.ricchieri.dao.interf.IPlaceDao;
import com.ricchieri.filter.PlaceFilter;
import com.ricchieri.model.Place;
import com.ricchieri.service.interf.IPlaceService;
import com.ricchieri.util.FacesUtil;

@Transactional(readOnly = true)
public class PlaceService implements IPlaceService, Serializable {
	private static final long serialVersionUID = 3772243592804966962L;
	IPlaceDao placeDao;

	public IPlaceDao getPlaceDao() {
		return placeDao;
	}

	public void setPlaceDao(IPlaceDao placeDao) {
		this.placeDao = placeDao;
	}

	@Override
	public Map<String, String> getComboPlaces() {
		PlaceFilter placeFilter = new PlaceFilter();
		List<Place> placesValues = getPlaceDao().getAllPlaces(placeFilter);

		HashMap<String, String> places = new HashMap<String, String>();

		for (Place place : placesValues) {
			places.put(FacesUtil.getMessage(place.getDescription()), String.valueOf(place.getId()));
		}
		
		return places;
	}

	@Override
	public List<Place> getAllPlaces(PlaceFilter placeFilter) {
		return getPlaceDao().getAllPlaces(placeFilter);
	}

	@Override
	public Place getPlaceById(PlaceFilter placeFilter) {
		return getPlaceDao().getPlaceById(placeFilter);
	}	
}
